t=int(input())
for o in range(t):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=sorted(a)
b=sorted(b)
d=0 i=j=0
while(i<n and j<n):
if a[i]==b[j]:
a[i]=0
b[j]=0
i+=1
j+=1
d+=1
elif a[i]<b[j]:
i+=1
else :
j+=1
ans=0
for i in range(len(a)):
if a[i]>9:
a[i]=len(str(a[i]))
ans+=1
for i in range(len(b)):
if b[i]>9:
b[i]=len(str(b[i]))
ans+=1
a=sorted(a)
b=sorted(b)
i=j=0
while(i<n and j<n):
if(a[i]==0 and b[i]==0):
i+=1
j+=1
elif a[i]==b[j]:
a[i]=0
b[j]=0
i+=1
j+=1
d+=1
elif a[i]<b[j]:
i+=1
else :
j+=1
v=0
for i in a:
if i==1:
v+=1
for i in b:
if i==1:
v+=1
ans+=((n-d)*2)-v
print(ans)
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
// const int N = 1000000;
// int ARR[N]efine debug(x)
ll M = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--)
{
ll n;
cin >> n;
map<ll, ll>a, b;
for (int i = 0; i < n; i++)
{
ll x;
cin >> x;
a[x]++;
}
for (int i = 0; i < n; i++)
{
ll x;
cin >> x;
b[x]++;
}
vector<ll>aa, bb;
for (auto el : a)
{
ll mini = min(a[el.first], b[el.first]);
a[el.first] -= mini;
b[el.first] -= mini;
for (int i = 0; i < a[el.first]; i++) aa.push_back(el.first);
for (int i = 0; i < b[el.first]; i++)
{
bb.push_back(el.first);
// b[el.first] = 0;
}
b[el.first] = 0;
}
for (auto elt : b)
{
for (int i = 0; i < b[elt.first]; i++)
bb.push_back(elt.first);
}
// for (int i = 0; i < aa.size(); i++)
// cout << aa[i] << " ";
// cout << '\n';
// for (int i = 0; i < bb.size(); i++)
// cout << bb[i] << " ";
// cout << '\n';
ll ans = 0;
for (int i = 0; i < aa.size(); i++)
{
if (aa[i] >= 10)
{
aa[i] = (int)(log10(aa[i]) + 1);
ans++;
}
}
for (int i = 0; i < bb.size(); i++)
{
if (bb[i] >= 10)
{
bb[i] = (int)(log10(bb[i]) + 1);
ans++;
}
}
// cout << ans << '\n';
// for (int i = 0; i < aa.size(); i++)
// cout << aa[i] << " ";
// cout << '\n';
// for (int i = 0; i < bb.size(); i++)
// cout << bb[i] << " ";
// cout << '\n';
map<ll, ll>ma, mb;
for (int i = 0; i < aa.size(); i++)
ma[aa[i]]++;
for (int i = 0; i < bb.size(); i++)
mb[bb[i]]++;
vector<ll>ca, cb;
for (auto el : ma)
{
ll mini = min(ma[el.first], mb[el.first]);
ma[el.first] -= mini;
mb[el.first] -= mini;
for (int i = 0; i < ma[el.first]; i++)
ca.push_back(el.first);
for (int i = 0; i < mb[el.first]; i++)
{
cb.push_back(el.first);
// mb[el.first] = 0;
}
mb[el.first] = 0;
}
for (auto ab : mb)
{
for (int i = 0; i < mb[ab.first]; i++)
cb.push_back(ab.first);
}
// for (int i = 0; i < ca.size(); i++)
// cout << ca[i] << " ";
// cout << '\n';
// for (int i = 0; i < cb.size(); i++)
// cout << cb[i] << " ";
// cout << '\n';
for (int i = 0; i < ca.size(); i++)
{
if (ca[i] != 1) ans++;
}
for (int i = 0; i < cb.size(); i++)
{
if (cb[i] != 1) ans++;
}
cout << ans << '\n';
}
}
85. Maximal Rectangle | 84. Largest Rectangle in Histogram |
60. Permutation Sequence | 42. Trapping Rain Water |
32. Longest Valid Parentheses | Cutting a material |
Bubble Sort | Number of triangles |
AND path in a binary tree | Factorial equations |
Removal of vertices | Happy segments |
Cyclic shifts | Zoos |
Build a graph | Almost correct bracket sequence |
Count of integers | Differences of the permutations |
Doctor's Secret | Back to School |
I am Easy | Teddy and Tweety |
Partitioning binary strings | Special sets |
Smallest chosen word | Going to office |
Color the boxes | Missing numbers |
Maximum sum | 13 Reasons Why |